
#pragma once


#include <Arduino.h>
// #include <Wire.h>
#include <SPI.h>
#include <stdlib.h>

// ioxx
#include <pin/avr_arduino.hpp>

// mega128_specific
#include <mega128_specific.hpp>

namespace m128 = mega128_specific;

// scheduler_basic
#include <scheduler_basic.hpp>
#include <scheduler_tick.hpp>

using TimeSource = scheduler_basic::ArduinoMsSource;
using TimeType = typename TimeSource::TimeType;
using TimeCycle = scheduler_basic::TimeCycle<TimeSource>;

constexpr uint8_t MAX_TASK_COUNT = 5;

using Scheduler = scheduler_basic::DelayCallback3<TimeSource, MAX_TASK_COUNT>;

// oled_basic_v2
// #include "oled_backend.hpp"
// #include "oled_basic_font.hpp"
// #include "oled_basic_v2.hpp"
// #include "oled_ssd13xx.hpp"

// namespace ob = oled_basic;

// U8g2
#include <u8g2lib.h>

// using U8Type = U8G2_SSD1306_128X64_NONAME_F_HW_I2C;
using U8Type = U8G2_SSD1309_128X64_NONAME0_F_4W_HW_SPI;

// modpash
#include "adu/basic_client.hpp"
#include "rtu/non_block_serial.hpp"

/////////////////////// PIN MAPPING /////////////////////////

constexpr auto LED_PIN_NUM = m128::LED_PIN;

constexpr auto RS485_DE_RE_PIN_NUM = 25;  // 485 收发器的DE/RE# 引脚

constexpr auto OLED_CS_PIN_NUM = 13;  // OLED 的 CS 引脚
constexpr auto OLED_DC_PIN_NUM = 12;  // OLED 的 DC 引脚
constexpr auto OLED_RST_PIN_NUM = 8;  // OLED 的 RST 引脚

// constexpr auto FONT_ROM_CS_PIN_NUM = 14;  // 字库芯片的CS 引脚

constexpr auto BUTTON_LEFT_PIN_NUM = 40;
constexpr auto BUTTON_RIGHT_PIN_NUM = 41;
constexpr auto BUTTON_UP_PIN_NUM = 42;
constexpr auto BUTTON_DOWN_PIN_NUM = 43;
constexpr auto BUTTON_OK_PIN_NUM = 44;

/////////////////////// MODBUS /////////////////////////

constexpr TimeType MODBUS_COUNT_TIMEOUT = 2000;  // 设置响应超时时间为2000 毫秒
constexpr TimeType MODBUS_CONFIG_TIMEOUT = 1000;  // 读取和写入配置参数时，超时1000 毫秒

#define Serial485 Serial1

constexpr uint32_t DEFAULT_BAUD = 9600;

/////////////////////// GLOBAL GLOBALS /////////////////////////

extern Scheduler dcb;

extern U8Type u8g2;

/////////////////////// INLINE TOOLS /////////////////////////
